#define _CRT_SECURE_NO_WARNINGS 1


//#include<set>
//#include<string>
//#include<iostream>
//
//using namespace std;
//
//int lengthOfLongestSubstring(string s)
//{
//    int size = s.size();
//    int left = 0, right = 0;
//    int Max = 0;
//    set<char> tree;
//    while (right < size)
//    {
//        if (tree.count(s[right]))
//        {
//            Max = max(right - left, Max);
//            left++;
//            right = left;
//        }
//        tree.insert(s[right]);
//        right++;
//    }
//    return Max;
//}
//
//int main()
//{
//    string s = " ";
//    cout << lengthOfLongestSubstring(s) << endl;
//	
//	return 0;
//}


#include<vector>
#include<iostream>

using namespace std;

int longestOnes(vector<int>& nums, int k)
{
    int size = nums.size();
    int left = 0, right = 0;
    int count = 0, Max = 0;
    while (right < size)
    {
        if (nums[right] == 0)
        {
            count++;
        }
        if (count > k)
        {
            Max = max(right - left, Max);
            while (count != 1)
            {
                if (left < size && nums[left] == 0)
                {
                    count--;
                }
                left++;
            }
            count = 0;
            right = --left;
        }
        right++;
    }
    return Max;
}

int main()
{
    vector<int> v = { 1,1,1,0,0,0,1,1,1,1,0 };
    cout << longestOnes(v, 2) << endl;

	return 0;
}